package Test1;

import java.util.ArrayList;
import java.util.Collections;
import java.util.concurrent.Callable;

public class lian_xi_Demo5 implements Callable<Integer> {
    ArrayList<Integer> list;
    public lian_xi_Demo5(ArrayList<Integer> list) {
        this.list = list;
    }
    @Override
    public Integer call() throws Exception {
        ArrayList<Integer> boxlist = new ArrayList<>();
        while(true){
            synchronized (Thread_Demo4.class) {
                if (list.size() == 0) {
                    System.out.println(Thread.currentThread().getName() + boxlist);
                    break;
                } else {
                    Collections.sort(list);
                    int prize = list.remove(0);
                    boxlist.add(prize);
                }
                Thread.sleep(500);
            }
        }
        if(boxlist.size() == 0){
            return null;
        }else{
            return Collections.max(boxlist);
        }
    }
}
